package com.eugene.ui.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.dialogs.ListDialog;
import org.eclipse.ui.handlers.HandlerUtil;

public class OpenJfaceDialog extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
		// Now a few standard message dialog
		MessageDialog.openConfirm(shell, "Confirm", "Please confirm");
		MessageDialog.openError(shell, "Error", "Error occured");
		MessageDialog.openInformation(shell, "Info", "Info for you");
		MessageDialog.openQuestion(shell, "Question", "Really, really?");
		MessageDialog.openWarning(shell, "Warning", "I warn you");

		// A Message Dialog with configurable buttons
		MessageDialog dialog = new MessageDialog(shell, "My Title", null,
				"My message", MessageDialog.ERROR, new String[] {
						"First choice", "Second choice", "Third choice" }, 0);
		int result = dialog.open();
		System.out.println(result);
		
//		ElementListSelectionDialog Dialog
		ElementListSelectionDialog dialog1 = new ElementListSelectionDialog(
				shell, new LabelProvider());
		dialog1.setElements(new String[] { "Linux", "Mac", "Windows" });
		dialog1.setTitle("Which operating system are you using");
		// User pressed cancel
		if (dialog1.open() != Window.OK) {
			return false;
		}
		Object[] result1 = dialog1.getResult();
		for (Object s : result1) {
			System.out.println(s.toString());
		}
//ListDialog, ElementTreeSelectionDialog and CheckTreeSelectionDialog
		ListDialog dialog2 = new ListDialog(shell);
		
		
		return null;

	}
	
//	@Override
//	public Object execute(ExecutionEvent event) throws ExecutionException {
//		try{
//			HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
//			.showView("com.eugene.ui.views.MarketVariableView", "1",IWorkbenchPage.VIEW_ACTIVATE);
//			
//		}
//		catch(PartInitException e){
//			
//		}
//		return null;
//		
//	}

}
